<?php


namespace App\Sevrice;
use Firebase\JWT\JWT;
use Firebase\JWT\Key;

class ApiJwt
{
    static private $key='2001a';
    //给指定用户颁发签名
    static function getToken($userInfo){
        $payload = [
            'iss' => 'http://example.org',
            'aud' => 'http://example.com',
            'iat' => 1356999524,
            'nbf' => 1357000000,
            'userInfo'=>$userInfo
        ];
        $jwt = JWT::encode($payload, self::$key, 'HS256');
        return $jwt;
    }
    //解析token获取用户信息
    static function decodeToken($jwt){
        $decoded = JWT::decode($jwt, new Key(self::$key, 'HS256'));
        $decoded_array = (array) $decoded;
        return $decoded_array['userInfo'];
    }
}